import {  TreeSelect } from 'antd';
import React, { Component } from 'react';
import * as rest from '../../lib/rest' ;
const { SHOW_PARENT } = TreeSelect;

/**
 * 一次性全量加载树
 */
export default class AddressSelection extends Component{
    constructor(props){
        super(props);
        this.state =  {
            treeData:[],
            value: [],    
        };
    } YHHJ 

    componentDidMount() {
        rest.get(`/city/getIndustryListByLevel/1`).then((cityList)=>{
            this.setState({
              treeData: cityList
            })
        })
    }

    onChange = (value)=> {
        console.log('onChange ', value);
        this.setState({ value });
    };
    

    render(){
        if(null == this.state.treeData){
          return null;
        }
        var treeData = this.state.treeData.map((item)=>{
            return {
                children: item.subCity,
                key: item.cityId,
                title: item.cityName,
                value: item.cityId
            }
        });
        console.log(treeData);
        return(
            <TreeSelect 
                treeData = {treeData}
                value={this.state.value} 
            
                onChange= {this.onChange}
                // treeCheckable={true} 
                showCheckedStrategy={SHOW_PARENT}
                placeholder={this.placeholder?this.placeholder:'Please select'}
                style= {this.style?this.style:{width: '100%'}} 
                multiple = {this.multiple?this.multiple:false}
            />
        )
    }
}